class MyDao {
    constructor(databaseManager,
        mongo_record_collection,
        mongo_record_error) {
        this.databaseManager = databaseManager;
        this.record_collection = mongo_record_collection;
        this.error_collection = mongo_record_error;
    }

    async addJobRecord(jobid, result, status) {
        let record = {
            jobid: jobid,
            result: result,
            status: status,
            createdDate: new Date()
        };
        const collection = await this.databaseManager.getCollection(this.record_collection);
        if (!collection) throw new Error('记录集合不存在');
        await collection.insertOne(record);
    }

    async addErrorRecord(content, error) {
        let errrecord = {
            msg: content,
            error: error,
            ocDate: new Date()
        };
        const collection = await this.databaseManager.getCollection(this.error_collection);
        if (!collection) throw new Error('错误记录集合不存在');
        await collection.insertOne(errrecord);
    }

    async isDatabaseHealthy() {
        try {
            const health = await this.databaseManager.healthCheck();
            return health.status === 'healthy';
        } catch (error) {
            console.error('数据库健康检查失败:', error);
            return false;
        }
    }
}

module.exports = MyDao;